#include "CChangeBackground.h"
#include "CRender.h"
#define TRANS_SPEED 0.5f
CChangeBackground CChangeBackground::Instance;
CChangeBackground::CChangeBackground()
{
interp.NextAlpha = 0.0f;
interp.CurrentAlpha = 1.0f;
	
	m_nCurrentBackGround = Egyptian; 

	m_nNextBackGround =  Egyptian;
	shape.MakeShape(Vec2(-20,-20),Vec2(20,20),1);
	backShape.MakeShape(Vec2(-20,-20),Vec2(20,20),1);

	WindowQuad1.MakeShape(Vec2(-15, 0), Vec2(-5, -10), 1);
	WindowQuad2.MakeShape(Vec2(5, 0), Vec2(15, -10), 1);
	WindowQuad3.MakeShape(Vec2(-5, 15), Vec2(5, 5), 1);
}
void CChangeBackground::LoadAllBackGround()
{
	 EgyptTex =  CTextureManager::GetInstance()->LoadTexture("img/backgrounds/back_egypt_sq.tga");
	 GothTex =  CTextureManager::GetInstance()->LoadTexture("img/backgrounds/back_gothic.tga");
	 MidEvTex =  CTextureManager::GetInstance()->LoadTexture("img/backgrounds/back_medieval.tga");

	 WindowOne = CTextureManager::GetInstance()->LoadTexture("img/columns/GothicWindow2.tga");
	 WindowTwo = CTextureManager::GetInstance()->LoadTexture("img/columns/GothicWindow3.tga");
}

void CChangeBackground::Transition(float fElapsedTime)
{

	if(m_nCurrentBackGround != m_nNextBackGround)
	{
		interp.NextAlpha += fElapsedTime * TRANS_SPEED;
		interp.CurrentAlpha -= fElapsedTime * TRANS_SPEED;

		if (interp.CurrentAlpha <= 0)
		{
			interp.CurrentAlpha = 1;
			interp.NextAlpha = 0;
			m_nCurrentBackGround = m_nNextBackGround;
		}
	}
	

}
void CChangeBackground::Render()
{
	switch (m_nCurrentBackGround)
	{
	case Egyptian:
		CRender::GetInstance()->DrawTex(EgyptTex,&shape,Vec2(0,0),-3, 0, false,eSHADER_TEXTURE,interp.CurrentAlpha, true);
		CRender::GetInstance()->DrawTex(MidEvTex,&backShape,Vec2(0,0),-3,0,false,eSHADER_TEXTURE,interp.NextAlpha, true);
		break;
	case MidEvil:
		CRender::GetInstance()->DrawTex(MidEvTex,&shape,Vec2(0,0),-3, 0, false,eSHADER_TEXTURE,interp.CurrentAlpha, true);
		CRender::GetInstance()->DrawTex(GothTex,&backShape,Vec2(0,0),-3,0,false,eSHADER_TEXTURE,interp.NextAlpha, true);
		//CRender::GetInstance()->DrawTex(WindowOne, &WindowQuad1, Vec2(0,0), -2, 0, false, eSHADER_TEXTURE, interp.NextAlpha, true);
		//CRender::GetInstance()->DrawTex(WindowOne, &WindowQuad2, Vec2(0,0), -2, 0, false, eSHADER_TEXTURE, interp.NextAlpha, true);
		//CRender::GetInstance()->DrawTex(WindowTwo, &WindowQuad3, Vec2(0,0), -2, 0, false, eSHADER_TEXTURE, interp.NextAlpha, true);
		break;
	case Gothic:
		CRender::GetInstance()->DrawTex(GothTex,&shape,Vec2(0,0),-3, 0, false,eSHADER_TEXTURE,interp.CurrentAlpha, true);
		CRender::GetInstance()->DrawTex(WindowOne, &WindowQuad1, Vec2(0,0), -2, 0, false, eSHADER_TEXTURE, interp.CurrentAlpha, true);
		CRender::GetInstance()->DrawTex(WindowOne, &WindowQuad2, Vec2(0,0), -2, 0, false, eSHADER_TEXTURE, interp.CurrentAlpha, true);
		CRender::GetInstance()->DrawTex(WindowTwo, &WindowQuad3, Vec2(0,0), -2, 0, false, eSHADER_TEXTURE, interp.CurrentAlpha, true);
		break;
	}

}